package presentation.playgameForm_UI;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.JWindow;
import javax.swing.Timer;

@SuppressWarnings("serial")
public class Message_UI extends JWindow
{
	private int score = 0;
	private int time = 0;
	private float opacity = 1;
	public Message_UI(boolean wordFound, int score, JToggleButton button)
	{
		this.score = score;
		setMainLayout();
		setMessage(wordFound);
		this.setLocationRelativeTo(button);
		this.getContentPane().setBackground(new Color(201, 228, 255));
		timer = new Timer(50, action);
		timer.start();
	}
	
	private ActionListener action = new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			time++;
			setOpacity(opacity -= 0.025);
			if(time == 40)
			{
				setVisible(false);
				timer.stop();
			}
		}
	};
	
	private JLabel message = new JLabel();
	private JPanel panel = new JPanel();
	
	private Timer timer;
	
	private void setMainLayout()
	{
		this.setLayout(null);
		this.add(panel);
		
		panel.setBorder(BorderFactory.createTitledBorder(""));
		panel.setBounds(1,1,200,40);
		panel.setBackground(new Color(201, 228, 255));
		message.setFont(new Font("Calibri", 1, 20));
		panel.setLayout(new FlowLayout(FlowLayout.CENTER));
		panel.add(message);
//		message.setBounds(1,1,198,48);
		
		this.setSize(202,42);
	}
	
	private void setMessage(boolean wordFound)
	{
		if(wordFound)
		{
			message.setText("SCORE: " + score);
		}
		else
		{
			message.setText("WORD NOT FOUND");
		}
	}
}
